#!/bin/bash
# author
# Treri <https://github.com/Treri>

msg=$(head -n 1 $1)

if echo $msg | grep -iqE "^Merge "; then
	exit 0
fi;

if echo $msg | grep -iqE "^Revert "; then
	exit 0
fi;

if echo $msg | grep -iqE "^(feat|fix|docs|style|refactor|perf|test|chore)(\([^()]{1,}\)){0,1}: .{1,}"; then
	exit 0
fi;

echo
echo -e "\033[41m 本次提交说明不能为空，必须下面的类型中 MSG:\033[0m Does not match \"<type>(<scope>): <subject>\" !"
echo
cat <<EOF
Available types and what it mean are list here

feat:     A new feature
fix:      A bug fix
docs:     Documentation only changes
style:    Changes that do not affect the meaning of the code
(white-space, formatting, missing semi-colons, etc)
refactor: A code change that neither fixes a bug or adds a feature
perf:     A code change that improves performance
test:     Adding missing tests
chore:    Changes to the build process or auxiliary tools
and libraries such as documentation generation

EOF
echo -e "Please read http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html"
echo

exit 1

